#include "NxModelServiceInstanceFactory.h"
#include "NxRunningLogFactory.h"

NJGIS::SERVICE::INjModelServiceInstance* NJGIS::SERVICE::NjModelServiceInstanceFactory::createModelServiceInstacnce(Json::Value jsData, const char* ip, int port)
{
	NJGIS::SERVICE::NjModelServiceInstance* pInstance = new NJGIS::SERVICE::NjModelServiceInstance(
		jsData["state"].asString().c_str(),
		jsData["event"].asString().c_str(),
		jsData["guid"].asString().c_str(),
		jsData["start"].asString().c_str(),
		jsData["ms"]["_id"].asString().c_str(),
		ip,
		port
		);
	return pInstance;
}

NJGIS::SERVICE::NjModelInstanceStatus NJGIS::SERVICE::NjModelServiceInstanceFactory::convertString2Status( const char* cstatus )
{
	std::string status = std::string(cstatus);
	if(status == "RUNNING")
	{
		return NJGIS::SERVICE::NjModelInstanceStatus::INSTA_RUNNING;
	}
	else if(status == "REQUESTING")
	{
		return NJGIS::SERVICE::NjModelInstanceStatus::INSTA_REQUESTING;
	}
	else if(status == "HANGING")
	{
		return NJGIS::SERVICE::NjModelInstanceStatus::INSTA_HANGING;
	}
	return NJGIS::SERVICE::NjModelInstanceStatus::INSTA_UNKNOWN;
}
